package com.invengo.module_check.ui.fragment.first_check.item;

import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.invengo.library_db.entity.module_check.RecordBean;
import com.invengo.module_check.ui.fragment.first_check.RecordViewModel;

import java.text.SimpleDateFormat;
import java.util.Date;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;

public class PosRecordItemViewModel extends ItemViewModel<RecordViewModel> {
    public SingleLiveEvent<RecordBean.ItemsDTO> bean = new SingleLiveEvent<>();
    public SingleLiveEvent<String> dateTime = new SingleLiveEvent<>();
    public PosRecordItemViewModel(@NonNull RecordViewModel viewModel, RecordBean.ItemsDTO bean) {
        super(viewModel);
        this.bean.postValue(bean);
        String date=null;
        if(bean.getDtOperateDate() instanceof Date) {
            date = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(bean.getDtOperateDate());
        }else {
            date=bean.getDtOperateDate().toString();
        }
        if(date!=null&&date.contains("T")) {
            date = date.replaceAll("T", " ");
        }
        String dtOperateDate = TextUtils.isEmpty(date) ? " " : date;
        dateTime.postValue(dtOperateDate);
    }
    public int getPosition() {
        return viewModel.getPosition(this) + 1;
    }

}
